package practice;

import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class _序列模式匹配_ {
    public static void main(String[] args) {
        _序列模式匹配_ c = new _序列模式匹配_();
        _序列模式匹配_.Solution s = c.getSolutin();
        Scanner scanner = new Scanner(System.in);
        int M = Integer.valueOf(scanner.nextLine());
        String[] arr = new String[M];
        while (M > 0 ){
            arr[--M] = scanner.nextLine();
        }
        s.arrsort(arr);
    }


    Solution getSolutin() {
        return new Solution();
    }

    class Solution {
        public void arrsort(String[] arr ){
            TreeMap<String,Integer> treeMap = new TreeMap<>();
            for (int i = 0; i < arr.length; i++) {
                int len = arr[i].length();
                treeMap.put(arr[i].substring(len-6,len),i);
            }

            Iterator iterator = treeMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry entry = (Map.Entry)iterator.next();
                System.out.println(entry.getKey());
            }
        }
    }
}
